package server;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Locale;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import classes.User;



import db.DB;
import db.DBmanager;

/**
 * Servlet implementation class SellStreetServlet
 */
public class SellStreetServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SellStreetServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String regRes="";
		//Locale loc= new Locale("he"); 
		request.setCharacterEncoding("ISO-8859-8");
		//request.setLocale(loc);
		//request.setContentType("text/html; charset=UTF-8");
		
		String userName=request.getParameterValues("userName")[0];
		String street=request.getParameterValues("streetNum")[0];
		
		
		PrintWriter out=response.getWriter();
		try {
			String streetName=DBmanager.getDB().sellStreet(userName,Integer.parseInt(street));
			DBmanager.getDB().insertMessage(userName,"You have sold "+streetName+" for "+DB.STREET_PRICE+"NIS","SELL");
			response.setStatus(200);
		} catch (SQLException e) {
			out.write("we have encountered problem with the selling process, please try later");
			response.setStatus(400);
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
